import Pages from '../../pages/pages.vue'
import { useStatistics , showMsg } from '../../../vuex/action'

export default {
  name: 'applyAccount',
  components: {
    'vue-pages': Pages
  },
  data() {
    return {
      list: [],
      totalSend: 0,
      totalGetUser: 0,
      totalUse: 0,
      totalUseUser: 0,
      pages: {
        start: 0,
        totalPages: 0,
        limit: 20
      }
    }
  },
  vuex: {
    actions: {
      xShowMsg: showMsg,
      xUseStatistics: useStatistics
    }
  },
  ready() {
    this.search({})
  },
  methods: {
    search({start=this.pages.start, limit=this.pages.limit}) {
      this.xUseStatistics({
        start: start,
        limit: limit
      })
        .then((res) => {
          this.totalSend = res.totalSend
          this.totalGetUser = res.totalGetUser
          this.totalUse = res.totalUse
          this.totalUseUser = res.totalUseUser
          this.list = res.list
          this.pages.totalPages = Math.ceil(res.totalCount / limit)
        })
        .catch((res) => {
          this.xShowMsg({
            type: 'danger',
            content: res.error_msg
          })
        })
    }
  }
}
